class Solution {
public:
    int maxProfit(vector<int>& p) {
        int m = p[0], res = 0;
        for (int c: p) {
            if (c < m) m = c;
            if (res < c - m) 
                res = c - m;
        }
        return res;
    }
};
